package com.qdsgjsfk.vision.viewmodel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.MutableLiveData;
import android.support.annotation.NonNull;

import com.qdsgjsfk.vision.ui.DeviceListActivity;
import com.rest.business.RestProxy;
import com.rest.response.DeviceResponse;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import com.qdsgjsfk.vision.util.NetUtil;

/**
 * Created by HP on 2019/11/11.
 */

public class DeviceViewModel extends AndroidViewModel {


    public DeviceViewModel(@NonNull Application application) {
        super( application );
    }

    public MutableLiveData<List<DeviceResponse.Device>> getmItems() {
        return mItems;
    }

    private final MutableLiveData<List<DeviceResponse.Device>> mItems = new MutableLiveData<>();


    /**
     * 接口名称：设备型号选择
     *
     * @time 2020/5/27 14:08
     */
    public void getDeviceList(long deviceType, DeviceListActivity deviceListActivity) {
        RestProxy.getInstance().getDevices( deviceType, new Observer<DeviceResponse>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DeviceResponse deviceResponse) {
                mItems.setValue( deviceResponse.data );
            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
                NetUtil.onError(e,getApplication());
            }

            @Override
            public void onComplete() {

            }
        } );
    }


}
